package com.yuntongxun.ecdemo.voicechat.comman;

import android.util.Log;

import com.google.gson.Gson;
import com.yuntongxun.ecdemo.voicechat.bean.GiftChatJson;
import com.yuntongxun.ecdemo.voicechat.util.CommonUtils;

/**
 * description：
 * author：liucanwen on 16/12/11 12:32
 * email：liucanwen@baibu.la
 */
public class GiftContacts {

    /**
     * 生成礼物聊天对话
     * @param giftUrl
     * @return
     */
    public static String getGiftContact(String giftUrl, String giftId, String giftName){

        GiftChatJson giftChatJson = new GiftChatJson();

        if(!CommonUtils.isEmpty(giftUrl)) {
            giftChatJson.setUrl(giftUrl);
        }

        if(!CommonUtils.isEmpty(giftId)){
            giftChatJson.setGiftId(giftId);
        }

        if(!CommonUtils.isEmpty(giftName)){
            giftChatJson.setName(giftName);
        }

        String result = new Gson().toJson(giftChatJson);
        Log.e("gift", result);

        return result;
    }

    /**
     * 是否是礼物json
     * @param json
     * @return
     */
    public static boolean isGiftJson(String json){

        if(!CommonUtils.isEmpty(json)){

            if(json.startsWith("[gift]")){
                return true;
            }
        }

        return false;

    }

    /**
     * 得到礼物json
     * @param json
     * @return
     */
    public static String getGiftJson(String json){

        if(!CommonUtils.isEmpty(json)){

            if(json.startsWith("[gift]")){

                String json2 = json.substring(json.indexOf("]") + 1, json.lastIndexOf("["));

                return json2;
            }
        }

        return null;

    }
}
